package com.game.cards;

import java.util.Collections;
import java.util.List;
import java.util.ArrayList;

import com.game.play.ActionQueue;
import com.game.play.Events;
import com.game.play.Game;
import com.game.play.Player;

public class Deck {
	private List<BaseCard> cards;
	private String title;
	private Game game;
	private Player owner;
	
	public Deck (Game game,String title)
	{
		this.cards = new ArrayList<BaseCard>();
		this.setGame(game);
		this.title = title;
	}
	public Deck clone()
	{
		return new Deck(this.game, this.title);
	}
	public int deckSize()
	{
		return cards.size();
	}
	public BaseCard draw(ActionQueue aq)
	{
		BaseCard temp = null;
		if (cards.size() > 0) {
		temp = cards.get(0);
		cards.remove(0);
		aq.addEvent(Events.drawcard.toString() + "," + this.owner.getName());
		}
		return temp;
	}
	public List<BaseCard> draw(int amount,ActionQueue aq)
	{
		List<BaseCard> temp = new ArrayList<BaseCard>();
		for (int i = 0; i < amount; i++)
		{
			temp.add(draw(aq));
		}
		return temp;
	}
	
	public void shuffle()
	{
		Collections.shuffle(this.cards);
	}
	public void addCard(BaseCard c)
	{
		c.setDeck(this);
		this.cards.add(c);
		
	}
	public void setOwner(Player p)
	{
		this.owner = p;
	}
	public Player getOwner()
	{
		return this.owner;
	}
	public List<BaseCard> getCards()
	{
		return this.cards;
	}
	
	public List<BaseCard> getMonsterCards()
	{
		List<BaseCard> temp = new ArrayList<BaseCard>();
		for (BaseCard c : this.cards)
		{
			if (c instanceof MonsterCard)
			{
				temp.add(c);
			}
		}
		return temp;
	}
	public List<BaseCard> getSpellCards()
	{
		List<BaseCard> temp = new ArrayList<BaseCard>();
		for (BaseCard c : this.cards)
		{
			if (c instanceof SpellCard)
			{
				temp.add(c);
			}
		}
		return temp;
	}
	public List<BaseCard> getTrapCards()
	{
		List<BaseCard> temp = new ArrayList<BaseCard>();
		for (BaseCard c : this.cards)
		{
			if (c instanceof TrapCard)
			{
				temp.add(c);
			}
		}
		return temp;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public Game getGame() {
		return game;
	}
	public void setGame(Game game) {
		this.game = game;
	}
}
